﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Database;
public partial class admin_ThemLK : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        var pm = new checkLogin();
        pm.redirectToLoginPage();
        if (!IsPostBack)
            {
                if (Session["tenkh"] == "Admin")
                {
                    Response.Redirect("Login.aspx");
                }
                else
                {
                    ddlLoaiLK.DataSource = LoaiLinhKien.DSLoaiLK().Tables[0];
                    ddlLoaiLK.DataTextField = "tenloailk";
                    ddlLoaiLK.DataValueField = "loailk";
                    ddlLoaiLK.DataBind();
                }
            }
        }

        protected void btAdd_Click(object sender, EventArgs e)
        {          
            
            float giaban = float.Parse(txtGiaBan.Text);
            string hinhanh;
            if (!String.IsNullOrEmpty(UpLoadHinhAnh.FileName))
            {
                String path = "~/images/" + UpLoadHinhAnh.FileName;
                UpLoadHinhAnh.SaveAs(MapPath(path));
                hinhanh = UpLoadHinhAnh.FileName.ToString();
            }
            else
            {
                hinhanh = "no_image.jpg";
            }
            int soluong = int.Parse(txtSoLuong.Text);            
            int loailk = int.Parse(ddlLoaiLK.SelectedValue.ToString());
            LinhKien lk = new LinhKien();
            lk.ThemLK(this.txtTenLK.Text,giaban, hinhanh, soluong, loailk);
            Response.Redirect("DanhSachLK.aspx");
        }

        protected void btCancel_Click(object sender, EventArgs e)
        {
            txtTenLK.Text = "";
            txtGiaBan.Text = "";            
            txtSoLuong.Text = "";
        }
    
}
